/*
 * $Id: HandshakeValidator.java,v 1.8 2009/08/13 16:16:58 afaichun Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.onwatch.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

import com.ge.healthcare.autosc.common.ASCLogger;
import com.ge.healthcare.autosc.onwatch.bean.HandshakeBean;

/**
 * 
 * @author 212042946
 * 
 */
public class HandshakeValidator extends BasePostValidator {

	public static final String REQUEST_TYPE = "Handshake";

	public boolean supports(Class clazz) {
		return clazz.equals(HandshakeBean.class);
	}

	public void validate(Object command, Errors errors) {
		super.validate(command, errors);
		HandshakeBean handshakeBean = (HandshakeBean) command;
		validateRequestType(handshakeBean, errors);
		ValidationUtils.rejectIfEmptyOrWhitespace(errors,
				"nextConnectTimeInMin", "required.nextConnectTimeInMin",
				"nextConnectTimeInMin is required");
	}

	protected void validateRequestType(HandshakeBean bean, Errors errors) {
		if (!REQUEST_TYPE.equalsIgnoreCase(bean.getRequestType())) {
			errors.reject("invalid.requestType", "Invalid request");
		}
	}
}
